'use strict';
/**
 * model
 */
import pagination from 'think-pagination';//引入分页插件

export default class extends think.model.base {

    //统计留言总数
    total(where) {
        let total = this.model('category').where(where).count();
        return total;
    }

    //category data list
    async dataList(where, order = 'ordernum desc,id desc', lv = 1) {
        //let total = await this.total();
        let dataList = await this.model('category').where(where).order(order).select();
        if (dataList) {
            
            //console.log(dataList);
            for (var i = 0; i < dataList.length; i++) {
                let findNextWhere = 'pid = ' + dataList[i]['id'] + ' and is_publish = 1';
                //console.log(findNextWhere);
                if (this.findData(findNextWhere)) {
                    dataList[i]['child'] =  await this.dataList(findNextWhere, order, lv + 1);
                } else {
                    dataList[i]['child'] = '';
                }
            }
        }
        return dataList;
    }

    //category obj
    findData(where) {
        let obj = this.model('category').where(where).find();
        return obj;
    }
}